package com.kang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kang.entity.Essay;
import com.kang.mapper.EssayMapper;
import com.kang.service.EssayService;
import com.kang.vo.ParamInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class EssayServiceImpl extends ServiceImpl<EssayMapper, Essay> implements EssayService {

    @Autowired
    private EssayMapper essayMapper;

    @Override
    public Page<Essay> selectPage(ParamInfo paramInfo) {
        Page<Essay> page = new Page<>(paramInfo.getPageNum(), paramInfo.getPageSize());
        QueryWrapper<Essay> wrapper = new QueryWrapper<>();
        wrapper.like(paramInfo.getTitle() != null,"title",paramInfo.getTitle());
        wrapper.eq(paramInfo.getParkId() != null,"park_id",paramInfo.getParkId());
        wrapper.between(!StringUtils.isEmpty(paramInfo.getStartTime()),"create_time",paramInfo.getStartTime(),paramInfo.getEndTime());
        wrapper.last("order by create_time desc");
        return essayMapper.selectPage(page,wrapper);
    }
}
